package hot_information.rss;


import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class Rss_parse {

	
	
	
	public void parseRss(){
		String xml_url = "http://sports.qq.com/others/rss_others.xml";    //腾讯体育新闻
		try {
			URL rss_url = new URL(xml_url);	
			HttpURLConnection conn = (HttpURLConnection) rss_url.openConnection();  //获取连接
			if(conn.getResponseCode()==200){  //链接成功
			InputStream in = conn.getInputStream();   //获取字节输入流
			InputStreamReader c_in = new InputStreamReader(in,"UTF-8");    //转换为字符流
		
			SAXReader reader = new SAXReader();     //saxreader创建SAX解析事件dom4j树
			Document   document = reader.read(c_in);    //读取给定流使用SAX文档

			 XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(new File(Rss_parse.class.getResource("/hot_information/rss").toURI().getPath()+"news.xml")),"UTF-8"));
		        //System.out.print(Rss_parse.class.getResource("/hot_information/rss").toURI().getPath()+"news.xml");
			 
		       
		        writer.write(document);    //写入到本地xml
		        in.close();
		        c_in.close();
			    writer.close();
			}else{
				System.out.println("RSS请求状态码："+conn.getResponseCode());
				
			}	
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
